/**
 * 计分牌
 */
export class ScorePanel {

    /**
     * 分数
     * @private
     */
    private _score: number = 0;

    /**
     * 等级
     * @private
     */
    private _level: number = 1;

    /**
     * 分数容器
     * @private
     */
    private _scoreSpan: HTMLElement;

    /**
     * 等级容器
     * @private
     */
    private _levelSpan: HTMLElement;

    /**
     * 最大等级
     * @private
     */
    private readonly _maxLevel: number;

    /**
     * 多少分升一级
     * @private
     */
    private readonly _step: number;

    constructor(maxLevel: number = 10, step: number = 10) {
        this._scoreSpan = document.getElementById("score")!;
        this._levelSpan = document.getElementById("level")!;
        this._maxLevel = maxLevel;
        this._step = step;
    }

    get level(): number {
        return this._level;
    }

    /**
     * 增加分数
     */
    public addScore(): void {
        this._scoreSpan.innerText = ++this._score + "";
        if (this._score % this._step === 0) {
            this.upLevel();
        }
    }

    /**
     * 提升等级
     */
    public upLevel(): void {
        if (this._level < this._maxLevel) {
            this._levelSpan.innerText = ++this._level + "";
        }
    }

}